/*
 * MyLogger.java
 *
 * Created on September 8, 2006, 10:18 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package zh.logging;

import java.util.logging.Level;

/**
 *
 * @author zheismann
 */
public class MyLogger
{
    private static final Level DEFAULTLEVEL = Level.FINE;
    private boolean ENABLED = true;
    private String name;
    private Level currentLevel = DEFAULTLEVEL;
    
    private MyLogger(String nm)
    {
        name = nm;
    }
    public static synchronized MyLogger getLogger(String name) 
    {
    	return new MyLogger(name);
    }
    
    public void log(String message)
    {
        if (isEnabled() && (currentLevel.intValue() >= DEFAULTLEVEL.intValue()))
        {
            System.err.println(name + " : " + currentLevel + " DEFAULTLEVEL: " + DEFAULTLEVEL + " : " + message);
        }
    }
    
    public void log(Level level, String message)
    {
        if (isEnabled() && (level.intValue() <= currentLevel.intValue()))
        {
            System.err.println(name + " : " +level.getName() + " : " + message);
        }
    }

    public boolean isEnabled()
    {
        return ENABLED;
    }

    public void setEnabled(boolean e)
    {
        this.ENABLED = e;
    }

    public void setLevel(Level level)
    {
        this.currentLevel = level;
    }
}
